package com.sf.bbs.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.sf.bbs.model.BBSModel;
import com.sf.bbs.service.BBSService;

public class BBSController extends MultiActionController {
	private BBSService bbsService;
	private BBSModel bbsModel;

	public void view(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		List resultList = bbsService.getBBSList(bbsModel);
		int totalCount = bbsService.getBBSListCount(bbsModel);
		System.out.println(JSONArray.fromObject(resultList).toString());
		Map data = new HashMap();
        data.put("totalCount", totalCount);
        data.put("datas", resultList);
        response.setHeader("Content-Type", "text/html; charset=UTF-8");
        response.getWriter().write(JSONObject.fromObject(data).toString());
	}
	public ModelAndView write(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("BBSController.writeBBS()");
		  String paramDataMap = request.getParameter("title");
		  String paramDataMap1 = request.getParameter("data");
//		  Map dataMap = (Map) JSONObject.toBean(JSONObject.fromObject(paramDataMap), Map.class, classMap);
		return null;	
	}
	public ModelAndView update(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("BBSController.updateBBS()");
		return null;
	}
	public ModelAndView delete(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		System.out.println("BBSController.deleteBBS()");
		return null;
	}
	public void setBbsService(BBSService bbsService) {
		this.bbsService = bbsService;
	}

	public BBSService getBbsService() {
		return bbsService;
	}
	
}
